package com.ler.yrmall.product.controller;

import com.ler.yrmall.product.entity.BrandEntity;
import com.ler.yrmall.product.service.BrandService;
import com.ler.yrmall.basic.Form;
import com.ler.yrmall.basic.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;


/**
 * 品牌
 * @author Leron
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Resource
    private BrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/find")
    public Result<?> list(Form request) {
        return Result.ok(brandService.find(request));
    }


    /**
     * 信息
     */
    @RequestMapping("/getById")
    public Result<?> getById(long id) {
        return Result.ok(brandService.getById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result<?> save(@Valid @RequestBody BrandEntity brand) {
        brandService.save(brand);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result<?> update(@RequestBody BrandEntity brand) {
        brandService.updateById(brand);
        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result<?> delete(@RequestBody Long[] brandIds) {
        brandService.removeByIds(Arrays.asList(brandIds));
        return Result.ok();
    }

}
